/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.bashsoft.nero.nameparser;

/**
 *
 * @author nero
 */
public class HtmlHelper {
    
    public static String getTournamentTemplate(String sport) {        
        return "\"games\\.php\\?sp\\=" + sport + "&amp;turnir\\=[0-9\\-]+\"";
    }
        
    public static String getTourTemplate(String sport) {        
        return "\"games\\.php\\?sp\\=" + sport + "&amp;turnir\\=[0-9\\-]+&amp;tour\\=[0-9\\-]+(&amp;tdate\\=[0-9]*)*\">([а-я ]+|1/[0-9]+|[0-9]{4})";
    }
    
    public static String getClubTemplate(String sport) {        
        return "\"club\\.php\\?sp\\=" + sport + "&amp;club\\=[0-9\\-]+(&amp;turnir\\=[0-9\\-]+)*\"";
    }
    
    public static String getPlayerTemplate(String sport) {        
        return "\"player\\.php\\?sp\\=" + sport + "&amp;player\\=[0-9\\-]+(&amp;turnir\\=[0-9\\-]+&amp;club\\=[0-9\\-]+)*\"";
    }
    
    public static String getTitleTemplate() {
        return ">[^<]+</h1>";
    }
    
    public static String getPlayerNationTemplate() {
        return "/>[^<]+</b></p><p";
    }
        
    public static String getIdByTournamentUrl(String url) {
        int index = url.indexOf("turnir=");
        index += "turnir=".length();
        String id = url.substring(index).trim();
        return id;
    }
    
    public static String getSubTournamentsBlockBegin() {
        return "<div class=\"sb_c_stat_years sb_c_bs_stl\">";
    }
    
    public static String getSubTournamentsBlockEnd() {
        return "</ul>";
    }
    
    public static String trim(String text) {
        int beginIndex = text.indexOf(">") + 1;
        int endIndex = text.indexOf("<");
        if (endIndex < 0) {
            if (beginIndex > 0) {
                endIndex = beginIndex - 1;
                beginIndex = 0;                
            }                
            else {
                endIndex = text.length();
            }
        }        
        try {
            text = text.substring(beginIndex, endIndex);
        }
        catch (Exception ex) {
            return null;
        }
        return text.replace("\"", "").replace("&amp;", "&").trim();
    }   
}
